package com.unbox.admin.controller;

import com.unbox.admin.entity.File;
import com.unbox.admin.fegin.FileFegin;
import com.unbox.admin.service.IFileService;
import com.unbox.common.response.UnboxResponse;
import com.unbox.common.table.UnBoxPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * <p>
 * <文件表业务Controller
 * </p>
 *
 * @author 王振宇
 * @since 2021-04-20
 */
@Api(tags = "文件表管理api")
@RestController
public class FileController implements FileFegin {

    @Autowired
    IFileService fileService;

    /**
     * 分页查询
     * @param file
     * @return
     */
    @ApiOperation(value = "分页查询列表")
    @Override
    public UnboxResponse<UnBoxPage> getPageList(File file, Integer pageNo, Integer pageSize) {
        UnBoxPage page = fileService.getPageList(file,pageNo, pageSize);
        return new UnboxResponse<>(page);
    }

    /**
     * 详情
     * @param file
     * @return
     */
    @ApiOperation(value = "查询明细")
    @Override
    public UnboxResponse<File> info(File file) {
        File fileVo = fileService.get(file);
        return new UnboxResponse<>(fileVo);
    }

    /**
     * 通过id数据查询数据
     * @param ids
     * @return
     */
    @ApiOperation(value = "通过ids进行in查询")
    @Override
    public UnboxResponse<List<File>> idsFiles(List<Integer> ids) {
        List<File> files = fileService.getIdsList(ids);
        return new UnboxResponse<>(files);
    }

    /**
     * 保存数据
     * @param file
     * @return
     */
    @ApiOperation(value = "保存数据")
    @Override
    public UnboxResponse<Boolean> save(File file) {
        Boolean flg = fileService.save(file);
        return new UnboxResponse<>(flg);
    }

    /**
     * 批量添加
     * @param files
     * @return
     */
    @ApiOperation(value = "批量保存数据")
    @Override
    public UnboxResponse<Boolean> batchSave(List<File> files) {
        Boolean flg = fileService.saveBatch(files);
        return new UnboxResponse<>(flg);
    }

    /**
     * 修改数据
     * @param file
     * @return
     */
    @ApiOperation(value = "修改数据")
    @Override
    public UnboxResponse<Boolean> update(File file) {
        Boolean flg = fileService.update(file);
        return new UnboxResponse<>(flg);
    }

    /**
     * 批量修改
     * @param files
     * @return
     */
    @ApiOperation(value = "批量修改数据")
    @Override
    public UnboxResponse<Boolean> batchUpdate(List<File> files) {
        Boolean flg = fileService.updateBatchById(files);
        return new UnboxResponse<>(flg);
    }

    /**
     * 删除数据
     * @param file
     * @return
     */
    @ApiOperation(value = "删除数据")
    @Override
    public UnboxResponse<Boolean> delete(File file) {
        Boolean flg = fileService.remove(file);
        return new UnboxResponse<>(flg);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除")
    @Override
    public UnboxResponse<Boolean> deleteBatch(List<Integer> ids) {
        Boolean flg = fileService.removeByIds(ids);
        return new UnboxResponse<>(flg);
    }
}

